import 'reflect-metadata'
import { CrowllerController, LoginController } from '../controller'
enum Methods {
  get = 'get',
  post = 'post',
}

export const get = getRequestDecorator(Methods.get)
export const post = getRequestDecorator(Methods.post)

// 通过一个工厂去返回get post put delete
function getRequestDecorator(type: Methods) {
  return function (path: string) {
    // target 原型
    return function (
      target: CrowllerController | LoginController,
      key: string
    ) {
      Reflect.defineMetadata('path', path, target, key)
      Reflect.defineMetadata('method', type, target, key)
    }
  }
}
